package hxy.bytecode.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 线程池的OOM测试
 *
 * @author eric
 * @description:
 * @date 12/19/19 3:34 PM
 */
public class ThreadPoolOOM {

    public static void main(String[] args) {
        // 这种创建线程池的方法，最大线程的数量是不可控的，会导致OOM
        ExecutorService es = Executors.newCachedThreadPool();
        int i = 0;
        while (true) {
            es.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println("新建");
                }
            });
        }
    }


}
